_Pragma("once")

#include <vector>
#include <utility>
#include <cstring>

#include "BasicDevice.h"
#include "SystemStatisticInfo.h"


using DataSliceHeader = std::pair<uint32_t, uint32_t>;

//void ff(BasicDevice*);

class StatisticInfoPersistor {

public:

    static constexpr uint32_t STRAT_FLAG = 0xffffffff;

    /** Default constructor */
    StatisticInfoPersistor(const std::string& path);

    StatisticInfoPersistor(void);

    /** Default destructor */
    ~StatisticInfoPersistor(void);

    bool prepareForWrite(void);

    bool saveToFile(std::vector<SystemStatisticInfo>& statisticInfos);


    bool openForRead(void);

    void closeForRead(void);


    /**
    return 1,seccuss and continue, 0 end, -1, error
    */
    int readFromFile(std::string& result);

protected:
    ssize_t stringifyStatisticInfo(const SystemStatisticInfo& info, char* buffer, const std::size_t length);


//    BasicDevice mfileFd;

    std::string mpath;
    std::string mpathFlag;

    BasicDevice* volatile mpreadFileFd;//BasicDevice::~BasicDevice
    char mbasicDeviceMemory[sizeof (BasicDevice)];

    bool mhasBeenSend = false;

//    std::unique_ptr<BasicDevice, decltype(ff)&> muni;

    DataSliceHeader header;
    ssize_t readed{0};

    int mi{9};
};



